import React, { useEffect, useRef } from 'react'

function useDebounce(call, breas) {
    const time = useRef(null)
    
    useEffect(() => {
        return () => {
            if (time.current)
            {
                clearInterval(time.current)
            }
        }
    },[])
    return (...ares) => {
        if (time.current)
            {
                clearInterval(time.current)
        }
        time.current = setInterval(() => {
            call(...ares)
        },breas)
  }
}

export default useDebounce
